from db import db
import datetime

class Log(db.Model):
    __tablename__ = 'log'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(255), nullable=False)
    type = db.Column(db.String(255), nullable=False)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)
                         
    def __init__(self, username, type):
        self.username = username
        self.type = type

    def to_dict(self):
        return {
            'id': self.id,
            'username': self.username,
            'type': self.type,
            "createTime": self.create_time.strftime('%Y-%m-%d %H:%M:%S')
        }